<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui">


<ui:composition template="/WEB-INF/templates/newsmaintemplate.xhtml">
	<ui:define name="metadata">
		<!-- save cagtThdId in sessionScope, DO NOT USE flash Scope.  -->
		<f:metadata>
			<f:viewParam name="#{constants.nameToValueMap.CATEGORY__THREAD_ID}" value="${sessionScope.ctgtThdId}"></f:viewParam>
		</f:metadata>
	</ui:define>
	<ui:define name="navigation">
		<h:panelGroup>
			<f:event type="preRenderComponent" listener="#{threadBackingBean.calculateNavMap()}" />
			<ui:include src="/navigation.xhtml"></ui:include>
		</h:panelGroup>
	</ui:define>

	<ui:define name="leftpage">
		<ui:remove>
			<p:carousel var="threadDB" value="#{threadDashBoardCacheService.getDashBoards(sessionScope.belongingCategory.categoryName)}"
				itemStyleClass="threadItemStyle" numVisible="6" styleClass="threadCarousel"
				rendered="#{!empty threadDashBoardCacheService.getDashBoards(sessionScope.belongingCategory.categoryName)}">
				<f:facet name="header">
					#{sessionScope.belongingCategory.categoryName}:#{msgs.TopPicker}
				</f:facet>
				<h:panelGroup layout="block">
					<h:link outcome="/thread/viewthread">
						<f:param name="id" value="#{threadDB.threadId}"></f:param>
						<div class="indexImg">
							<img class="dealPic" src="#{threadDB.picturePathURL}" />
						</div>
					</h:link>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="block">
					<h:link outcome="/thread/viewthread" value="#{threadDB.threadSubject}">
						<f:param name="id" value="#{threadDB.threadId}"></f:param>
					</h:link>
					<h:outputText value="#{threadDB.price}" styleClass="price" rendered="#{!empty threadDB.price}"></h:outputText>
					<h:outputText value="at #{threadDB.storeName}" styleClass="storeName" rendered="#{!empty threadDB.storeName}"></h:outputText>
					<h:graphicImage name="TopicHot.gif" library="images" rendered="#{(threadDB.markedHot)}" />
				</h:panelGroup>
			</p:carousel>
		</ui:remove>
		<div class="left_toptwo">
			<h2>
				#{sessionScope.belongingCategory.categoryName}<span class="right"> <p:button value="#{msgs.postNewThread}"
						outcome="/thread/createthread4AllCategory" styleClass="bigButton">
					</p:button>
				</span>
			</h2>
			<h:form>
				<p:dataTable id="datatable" var="thread" value="#{threadBackingBean.lazyThreadDataModel}" paginator="true" rows="30" lazy="true"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}  {PageLinks}  {CurrentPageReport} {NextPageLink} {LastPageLink}"
					rowsPerPageTemplate="5,10,15" tableStyleClass="tab_two" paginatorPosition="bottom"
					rowStyleClass="#{thread.type.toString().equals(constants.nameToValueMap.Thread_Type_Regular)? 'whiteBackGround' : 'announceThreadRow'}"
					styleClass="datatable" first="#{sessionScope.FIRST}">
					<p:column headerText="#{msgs.threadSubjectLabel}" styleClass="announceMainColumn"
						rendered="#{!thread.type.toString().equals(constants.nameToValueMap.Thread_Type_Regular)}">
						<h:panelGrid columns="2" columnClasses="smallCell" styleClass="tab_three">
							<h:panelGroup styleClass="thumbnail">
								<div class="imgWrapper" title="Announcement">
									<h:graphicImage name="speaker.jpg" library="images" styleClass="dealpicInListing"></h:graphicImage>
								</div>
							</h:panelGroup>
							<h:panelGroup styleClass="txt" layout="block">
								<h:link outcome="/thread/viewthread" styleClass="subject" rendered="#{!thread.topped}">
									<f:param name="id" value="#{thread.id}"></f:param>
									<h:outputFormat value=" #{thread.subject}."></h:outputFormat>
									<h:outputText value=" #{thread.price}" styleClass="priceInList"></h:outputText>
									<h:graphicImage name="TopicHot.gif" library="images" rendered="#{(thread.markedHot)}" />
								</h:link>
							</h:panelGroup>
						</h:panelGrid>
					</p:column>
					<p:column headerText="#{msgs.threadSubjectLabel}" styleClass="mainColumn"
						rendered="#{thread.type.toString().equals(constants.nameToValueMap.Thread_Type_Regular)}">
						<h:panelGrid columns="2" columnClasses="smallCell" styleClass="tab_three">
							<h:panelGroup styleClass="thumbnail" rendered="#{! empty thread.thumbPicURL}">
								<h:link outcome="viewthread">
									<f:param name="id" value="#{thread.id}"></f:param>
									<img src="#{thread.thumbPicURL}" class="dealpicInListing" />
								</h:link>
							</h:panelGroup>
							<h:panelGroup styleClass="txt" layout="block">
								<h:link outcome="viewthread" styleClass="subject" rendered="#{!thread.topped}">
									<f:param name="id" value="#{thread.id}"></f:param>
									<h:outputFormat value=" #{thread.subject}."></h:outputFormat>
									<h:outputText value=" #{thread.price}" styleClass="priceInList"></h:outputText>
									<h:graphicImage name="TopicHot.gif" library="images" rendered="#{(thread.markedHot)}" />
								</h:link>
								<h:link outcome="/thread/viewthread" styleClass="subject bold" rendered="#{thread.topped}">
									<f:param name="id" value="#{thread.id}"></f:param>
									<h:outputFormat value=" #{thread.subject}."></h:outputFormat>
									<h:outputText value=" #{thread.price}" styleClass="priceInList"></h:outputText>
									<h:graphicImage name="TopicHot.gif" library="images" rendered="#{(thread.markedHot)}" />
								</h:link>
								<h:graphicImage name="TopTopic.gif" library="images" rendered="#{thread.topped}" />
							</h:panelGroup>
						</h:panelGrid>
					</p:column>
					<p:column headerText="#{msgs.Rating}" sortBy="#{thread.rating}" styleClass="nonMainColumn">
						<h:panelGroup id="ratingGroup">
							<p:rating id="ratingId" readonly="true" stars="5" value="#{threadBackingBean.getRating(thread.id)}">
							</p:rating>
							<p:tooltip for="ratingId" showEffect="fade" id="ratingTip"
								value="Score: #{threadBackingBean.getRating(thread.id)} Votes: #{threadBackingBean.getRating(thread.id)} "></p:tooltip>
						</h:panelGroup>
					</p:column>

					<p:column headerText="#{msgs.threadReplyHitLabel}" sortBy="#{thread.numberOfReplies}" styleClass="nonMainColumn">
						<h:outputText value='#{thread.numberOfReplies}/#{thread.numberOfView}' escape="false"></h:outputText>
					</p:column>

					<p:column headerText="#{msgs.threadLastUpdateLabel}" sortBy="#{thread.lastReplyTime}" styleClass="nonMainColumn">
						<h:panelGroup rendered="#{thread.lastReplyTime!=null}">
							<h:outputText value="#{thread.lastReply.owner.userId}" styleClass="block" />
							<h:outputFormat value="#{thread.lastReplyTime}">
								<f:convertDateTime dateStyle="medium" timeStyle="short" type="both" />
							</h:outputFormat>
						</h:panelGroup>
						<h:panelGroup rendered="#{thread.lastReplyTime==null}">
							<h:outputText value="--/--" />
						</h:panelGroup>
					</p:column>
					<p:column headerText="#{msgs.threadAuthorLabel}" rendered="#{threadBackingBean.ownerForCurrCategory || login.userInSysadmin}"
						styleClass="nonMainColumn">
						<p:commandButton value="#{msgs.deleteButton}" actionListener="#{threadBackingBean.deleteThread(thread)}" update="@form" process="@form">
						</p:commandButton>

						<p:commandButton value="#{msgs.Top_Button}" actionListener="#{threadBackingBean.topThread(thread,true)}" process="@form" update="@form"
							rendered="#{!thread.topped}">
						</p:commandButton>
						<p:commandButton value="#{msgs.Untop_Button}" actionListener="#{threadBackingBean.topThread(thread,false)}" process="@form" update="@form"
							rendered="#{thread.topped}">
						</p:commandButton>

						<p:commandButton value="#{msgs.DashBoard}" actionListener="#{threadBackingBean.dashBoardThread(thread)}" process="@form" update="@form"
							rendered="#{!thread.onDashBoard}">
						</p:commandButton>
						<p:commandButton value="#{msgs.OutDashBoard}" actionListener="#{threadBackingBean.unDashBoardThread(thread)}" process="@form" update="@form"
							rendered="#{thread.onDashBoard}">
						</p:commandButton>
					</p:column>

				</p:dataTable>
				<div class="loading">
					<p:blockUI block="datatable" trigger="datatable">
				#{msgs.Loading}<br />
						<p:graphicImage value="/resources/images/ai.gif" style="position:fixed; left:200px;" />
					</p:blockUI>
				</div>
				<div class="postButton">
					<p:button value="#{msgs.postNewThread}" outcome="createthread">
					</p:button>
				</div>

			</h:form>
		</div>
		<ui:include src="/ad/leaderboard.xhtml"></ui:include>

	</ui:define>
	<ui:define name="rightpage">
		<div class="section block">
			<h:form>

				<p:dataList value="#{threadBackingBean.newestThreads}" var="thread" itemType="disc" styleClass="rightList">
					<f:event type="preRenderComponent" listener="#{threadBackingBean.retrieveNewestThread()}" />
					<f:facet name="header">#{msgs.POPULARDEAL}</f:facet>
					<div>
						<img class="nr1_tableft" src="#{thread.thumbPicURL}" />
					</div>
					<div class="nr1_tabright">
						<h3>
							<div class="listRightPage">
								<h:link value="#{thread.subject}" outcome="/thread/viewthread" styleClass="longstyle">
									<f:param name="id" value="#{thread.id}"></f:param>
								</h:link>
							</div>
						</h3>
						<h:panelGroup layout="block">
							<p:rating id="ratingId" readonly="true" stars="5" value="#{threadBackingBean.getRating(thread.id)}">
							</p:rating>
							<p:tooltip for="ratingId" showEffect="fade" id="ratingTip"
								value="Score: #{threadBackingBean.getRating(thread.id)} Votes: #{threadBackingBean.getVotes(thread.id)} "></p:tooltip>
						</h:panelGroup>
					</div>

				</p:dataList>
			</h:form>
		</div>
	</ui:define>

</ui:composition>

</html>